package com.finer.service.impl;

import com.finer.dao.FinerSaleRequestDetailDao;
import com.finer.entity.sell.FinerSaleRequestDetail;
import com.finer.service.FinerSaleRequestDetailService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 销售申请详情表(FinerSaleRequestDetail)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:39
 */
@Service("finerSaleRequestDetailService")
public class FinerSaleRequestDetailServiceImpl implements FinerSaleRequestDetailService {
    @Resource
    private FinerSaleRequestDetailDao finerSaleRequestDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FinerSaleRequestDetail queryById(Integer id) {
        return this.finerSaleRequestDetailDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param finerSaleRequestDetail 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerSaleRequestDetail> queryByPage(FinerSaleRequestDetail finerSaleRequestDetail, PageRequest pageRequest) {
        long total = this.finerSaleRequestDetailDao.count(finerSaleRequestDetail);
        return new PageImpl<>(this.finerSaleRequestDetailDao.queryAllByLimit(finerSaleRequestDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerSaleRequestDetail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerSaleRequestDetail insert(FinerSaleRequestDetail finerSaleRequestDetail) {
        this.finerSaleRequestDetailDao.insert(finerSaleRequestDetail);
        return finerSaleRequestDetail;
    }

    /**
     * 修改数据
     *
     * @param finerSaleRequestDetail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerSaleRequestDetail update(FinerSaleRequestDetail finerSaleRequestDetail) {
        this.finerSaleRequestDetailDao.update(finerSaleRequestDetail);
        return this.queryById(finerSaleRequestDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.finerSaleRequestDetailDao.deleteById(id) > 0;
    }
}
